<form name="form_group" id="form_group" method="post" action="<?php echo url_for('mailing_group/save'); ?>">
<table class="form">
	<tbody>
		<tr>
			<th><?php echo $form['nm_mailing_group']->renderLabel() ?></th>
			<td>
				<?php echo $form['nm_mailing_group'] ?> 
				<?php echo form_error('mailing_group[nm_mailing_group]'); ?>
			</td>
		</tr>
	</tbody>
</table>
</form>

<script type="text/javascript">
function salvarGrupo(){
	var selectElement = $('#mailing_list_id_mailing_group');
	var form = $('#form_group');
	if($('#mailing_group_nm_mailing_group').val())
	{
		$.ajax({
			type: "POST",
			dataType: "json",
   			url: form.attr("action"),
  			data: form.serialize(),
   			success: function(response)
   			{
				if(response.id_mailing_group)
				{
					var opt = $('<option />', {
            			value: response.id_mailing_group,
            			text: response.nm_mailing_group
            		});
            		opt.appendTo( selectElement );

					$('#mailing_list_id_mailing_group option:last').attr('selected', 'selected');
					$('#mailing_group_nm_mailing_group').val('');
					$("#modal-content").dialog('close');
					System.messagedata.alert('msgSucesso', 'Grupo adicionado com sucesso!', 'Sucesso');
				} else {
					System.messagedata.alert('msgErro', response.error, 'Erro!', '#modal-content');
				}
   			}
		});
	} else {
		System.messagedata.alert('msgAlerta', 'O campo nome é obrigatório.', 'Atenção!', '#modal-content');
	}
};
</script>